// var i;
// var $bundleConfig = require("./BundleConfig");
// var $resKeeper = require("./ResKeeper");
// var $commonUtils = require("./CommonUtils");
// var $excel = require("./Excel");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var f = cc._decorator;
// var g = f.ccclass;
// var _ = f.property;
// var y = f.inspector;
// var m = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.icon = null;
//         t.quality = null;
//         t.countLb = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {};
//     t.prototype.initUi = function (e, t) {
//         return __awaiter(this, void 0, void 0, function () {
//             var o;
//             var n;
//             var i;
//             var a = this;
//             return __generator(this, function (r) {
//                 switch (r.label) {
//                     case 0:
//                         switch (e) {
//                             case $hallGlobalVariable.default.goldId:
//                                 return [3, 1];
//                             case 12345:
//                                 return [3, 3];
//                         }
//                         return [3, 5];
//                     case 1:
//                         return [
//                             4,
//                             this._loadRes($bundleConfig.BundleNames.Common, "res/ui/tu/goldIcon", cc.SpriteFrame)
//                         ];
//                     case 2:
//                         o = r.sent();
//                         this._loadRes($bundleConfig.BundleNames.Common, "res/quality/quality_m_1", cc.SpriteFrame).then(
//                             function (e) {
//                                 a.quality.spriteFrame = e;
//                             }
//                         );
//                         this.icon.spriteFrame = o;
//                         return [3, 6];
//                     case 3:
//                         return [4, this._loadRes($bundleConfig.BundleNames.Common, "res/ui/tu/jifen", cc.SpriteFrame)];
//                     case 4:
//                         n = r.sent();
//                         this._loadRes($bundleConfig.BundleNames.Common, "res/quality/quality_m_3", cc.SpriteFrame).then(
//                             function (e) {
//                                 a.quality.spriteFrame = e;
//                             }
//                         );
//                         this.icon.spriteFrame = n;
//                         return [3, 6];
//                     case 5:
//                         i = $excel.Excel.shuiguo(e).quality;
//                         this._loadRes(
//                             $bundleConfig.BundleNames.Common,
//                             "res/player/player" + (e - 1e3) + "_1",
//                             cc.SpriteFrame
//                         ).then(function (e) {
//                             a.icon.spriteFrame = e;
//                             $commonUtils.default.LimitSpriteMaxSize(a.icon, 100);
//                         });
//                         this._loadRes(
//                             $bundleConfig.BundleNames.Common,
//                             "res/quality/quality_" + i,
//                             cc.SpriteFrame
//                         ).then(function (e) {
//                             a.quality.spriteFrame = e;
//                         });
//                         return [3, 6];
//                     case 6:
//                         this.countLb.string = "×" + t;
//                         return [2];
//                 }
//             });
//         });
//     };
//     __decorate([_(cc.Sprite)], t.prototype, "icon", void 0);
//     __decorate([_(cc.Sprite)], t.prototype, "quality", void 0);
//     __decorate([_(cc.Label)], t.prototype, "countLb", void 0);
//     return __decorate([g], t);
// })($resKeeper.default);
// exports.default = m;


// import { BundleNames } from "./BundleConfig";
// import ResKeeper from "./ResKeeper";
// import CommonUtils from "./CommonUtils";
// import { Excel } from "./Excel";
// import HallGlobalVariable from "./HallGlobalVariable";

// const { ccclass, property, inspector } = cc._decorator;

// /**
//  * 类，用于初始化界面元素，包括图标、品质与数量标签。建议类名：UIInitializer
//  */
// @ccclass
// class UI_GameOverItem extends ResKeeper {
//     @property(cc.Sprite)
//     public icon: cc.Sprite | null = null;

//     @property(cc.Sprite)
//     public quality: cc.Sprite | null = null;

//     @property(cc.Label)
//     public countLb: cc.Label | null = null;

//     /**
//      * 组件启用时的回调函数。
//      * 建议方法名：onComponentEnable
//      */
//     onEnable() {
//         // 此处定义组件启用时的逻辑
//     }

//     /**
//      * 初始化界面，根据传递的ID和数量，设置界面的图标和品质。
//      * @param {number} id 项目ID
//      * @param {number} count 数量
//      * 建议方法名：initializeUI
//      */
//     async initUi(id: number, count: number) {
//         let iconRes: cc.SpriteFrame | null;
//         let qualityRes: cc.SpriteFrame | null;

//         switch (id) {
//             case HallGlobalVariable.goldId:
//                 iconRes = (await this._loadRes(BundleNames.Common, "res/ui/tu/goldIcon", cc.SpriteFrame)) as cc.SpriteFrame;
//                 this.quality.spriteFrame = (await this._loadRes(BundleNames.Common, "res/quality/quality_m_1", cc.SpriteFrame)) as cc.SpriteFrame;
//                 this.icon.spriteFrame = iconRes;
//                 break;
//             case 12345:
//                 iconRes = (await this._loadRes(BundleNames.Common, "res/ui/tu/jifen", cc.SpriteFrame)) as cc.SpriteFrame;
//                 this.quality.spriteFrame = (await this._loadRes(BundleNames.Common, "res/quality/quality_m_3", cc.SpriteFrame)) as cc.SpriteFrame;
//                 this.icon.spriteFrame = iconRes;
//                 break;
//             default:
//                 const qualityIndex = Excel.shuiguo(id).quality;
//                 this.icon.spriteFrame = (await this._loadRes(BundleNames.Common, "res/player/player" + (id - 1000) + "_1", cc.SpriteFrame)) as cc.SpriteFrame;
//                 CommonUtils.LimitSpriteMaxSize(this.icon, 100);
//                 this.quality.spriteFrame = (await this._loadRes(BundleNames.Common, "res/quality/quality_" + qualityIndex, cc.SpriteFrame)) as cc.SpriteFrame;
//                 break;
//         }
//         this.countLb.string = "×" + count;
//     }

//     protected async _loadRes(bundleName: string, path: string, type: typeof cc.Asset): Promise<cc.Asset> {
//         // 使用资源管理器加载资源的逻辑
//         // 这里是一个伪代码，具体实现根据项目需要进行调整
//         return new Promise < cc.Asset > ((resolve, reject) => {
//             cc.assetManager.loadBundle(bundleName, (err, bundle) => {
//                 if (err) {
//                     reject(err);
//                     return;
//                 }
//                 bundle.load(path, type, (err, asset) => {
//                     if (err) {
//                         reject(err);
//                     } else {
//                         resolve(asset);
//                     }
//                 });
//             });
//         });
//     }
// }

// export default UI_GameOverItem;

import { BundleNames } from "./BundleConfig";
import ResKeeper from "./ResKeeper";
import CommonUtils from "./CommonUtils";
import { Excel } from "./Excel";
import FruitDataManager from "./HallGlobalVariable";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 类，用于初始化界面元素，包括图标、品质与数量标签。
 * 建议类名：UIInitializer
 */
@ccclass
class ViewGameOverItem extends ResKeeper {
    @property(cc.Sprite)
    public icon: cc.Sprite | null = null;

    @property(cc.Sprite)
    public quality: cc.Sprite | null = null;

    @property(cc.Label)
    public countLb: cc.Label | null = null;

    /**
     * 组件启用时的回调函数。
     * 建议方法名：onComponentEnable
     */
    onEnable() {
        // 此处定义组件启用时的逻辑
        // 目前该回调没有实现内容，可以在需要时添加具体的实现逻辑。
    }

    /**
     * 初始化界面，根据传递的ID和数量，设置界面的图标和品质。
     * @param {number} id 项目ID
     * @param {number} count 数量
     * 建议方法名：initializeUI
     */
    async initUI(itemId: number, itemCount: number) {
        let loadedIcon: cc.SpriteFrame | null;
        let loadedQuality: cc.SpriteFrame | null;

        switch (itemId) {
            case FruitDataManager.goldId:
                loadedIcon = (await this._loadRes(BundleNames.Common, "res/ui/tu/goldIcon", cc.SpriteFrame)) as cc.SpriteFrame;
                this.quality.spriteFrame = (await this._loadRes(BundleNames.Common, "res/quality/quality_m_1", cc.SpriteFrame)) as cc.SpriteFrame;
                this.icon.spriteFrame = loadedIcon;
                break;
            case 12345:
                loadedIcon = (await this._loadRes(BundleNames.Common, "res/ui/tu/jifen", cc.SpriteFrame)) as cc.SpriteFrame;
                this.quality.spriteFrame = (await this._loadRes(BundleNames.Common, "res/quality/quality_m_3", cc.SpriteFrame)) as cc.SpriteFrame;
                this.icon.spriteFrame = loadedIcon;
                break;
            default:
                const qualityIndex = Excel.shuiguo(itemId).quality;
                this.icon.spriteFrame = (await this._loadRes(BundleNames.Common, "res/player/player" + (itemId - 1000) + "_1", cc.SpriteFrame)) as cc.SpriteFrame;
                CommonUtils.limitSpriteSize(this.icon, 100);
                this.quality.spriteFrame = (await this._loadRes(BundleNames.Common, "res/quality/quality_" + qualityIndex, cc.SpriteFrame)) as cc.SpriteFrame;
                break;
        }
        this.countLb.string = "×" + itemCount;
    }

    /**
     * 使用资源管理器加载资源。
     * @param {string} bundleName 包名
     * @param {string} path 资源路径
     * @param {typeof cc.Asset} type 资源类型
     * @returns {Promise<cc.Asset>}
     * 建议方法名：loadResource
     */
    protected async _loadRes(bundleName: string, path: string, type: typeof cc.Asset): Promise<cc.Asset> {
        return new Promise<cc.Asset>((resolve, reject) => {
            cc.assetManager.loadBundle(bundleName, (bundleLoadError, loadedBundle) => {
                if (bundleLoadError) {
                    reject(bundleLoadError);
                    return;
                }
                loadedBundle.load(path, type, (resourceLoadError, loadedAsset) => {
                    if (resourceLoadError) {
                        reject(resourceLoadError);
                    } else {
                        resolve(loadedAsset);
                    }
                });
            });
        });
    }
}

export default ViewGameOverItem;